<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">
<h:head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" ></meta>
	<h:outputStylesheet name="styleSheet.css" library="css" />
	<h:outputScript name="javascript.js" library="javascript" />

</h:head>
<style type="text/css">
	.rf-pb-prgs { 
		 background-color: red !important;	 
		 background-image: url(./resources/images/bg-bubplastic-h-blue.gif)
		 }
	.rf-pb-rmng { 
	 	width: 166px !important;
	    height: 13px !important;
	    background-color:white !important;
	    border-style: none;
	    }
	    
	.divTextCenter {
		text-align: center;
		font-weight: bold;
	} 
</style>
<h:body>

	<ui:include src="/WEB-INF/template/barraSuperior.xhtml" />
	<div class="body_center">

		<div style="float: left; width: 17%;">
		
			<h2 class="h2_right">Área de Acesso</h2>
			<div class="div_body">
				<h:form id="loginForm" rendered="#{!userSession.logged}">						
					<h:outputLabel value="Usuário:" /><br />
					<h:inputText value="#{loginMB.usuarioBean.login}" id="txtLogin" maxlength="70" style="width=90%"/><br />
					
					<h:outputLabel value="Senha:" /><br />
					<h:inputSecret value="#{loginMB.usuarioBean.senha}" id="txtSenha" maxlength="30" style="width=90%"/><br />
					
					<h:commandButton value="Logar" action="#{loginMB.logar}"/>
					<h:commandButton value="Cadastrar" action="#{loginMB.cadastrar}"/>
					
				</h:form>
				<h:form rendered="#{userSession.logged}">
					<h:outputText value="Seja bem vindo #{userSession.usuarioBean.nome}!"/>
					<br />
					<h:commandButton value="Sair..." action="#{loginMB.sair}"/>
					<h:commandButton value="Dados Pessoais" action="#{loginMB.dadosPessoais()}"></h:commandButton>
				</h:form>
			</div>

			<a4j:region rendered="#{userSession.logged}">
			<h2 class="h2_right"><h:graphicImage library="botaoFavoritos.png" url="/resources/images/botaoFavoritos.png" width="15" height="15"></h:graphicImage> Favoritos</h2>
			<div class="div_right">
								<div id="cssmenu">
					<ul>
						<a4j:repeat var="categoria" value="#{loginMB.categoriasUsuario}">
							<li><h:link  outcome="index">
									<f:param name="IdCategoria" value="#{categoria.categoria.idCategoria}" />
								#{categoria.categoria.descricao}
								</h:link></li>
						</a4j:repeat>
					</ul>
				</div>
			</div>
			</a4j:region>
			
			<h2 class="h2_right">Enquete</h2>
				<div class="div_right">
				<h:form id="formEnqueteOpcao" >										
					<a4j:region rendered="#{enqueteMB.navegacao != true}">
						<h:outputLabel rendered="#{empty enqueteMB.ultimaEnqueteAtiva}" value="Nenhuma enquete disponível no momento."/>
						<a4j:repeat value="#{enqueteMB.ultimaEnqueteAtiva[0]}" var="enquete">						
							<h:outputLabel>#{enquete.questao}</h:outputLabel>					
						</a4j:repeat>																								
						<c:if test="#{!empty enqueteMB.ultimaEnqueteAtiva}">							
							<h:selectOneRadio id="enquete" value="#{enqueteMB.valorSelecionado}" layout="pageDirection">
								<f:selectItem itemLabel="Sim" itemValue="1"/>								
								<f:selectItem itemLabel="Não" itemValue="2"/>
							</h:selectOneRadio>							
							
							<h:commandButton value="Votar" action="#{enqueteMB.votar}"  render="formEnqueteOpcao formEnqueteResultado"></h:commandButton>
		        			<h:commandButton value="Resultado" action="#{enqueteMB.resultadoEnquete}" render="formEnquete2 formEnquete"></h:commandButton>	        			
	        			</c:if>
        			</a4j:region>
        			
        			<rich:notifyMessages stayTime="2000" nonblocking="true" />
        			</h:form>
        			<h:form id="formEnqueteResultado" >
        			<a4j:region rendered="#{enqueteMB.navegacao eq true}" id="regionResultado">																						
						<c:if test="#{enqueteMB.description != 'nenhum'}">
							<div class="divTextCenter">
								<h:outputText value="Resultado" />
							</div>							
						</c:if>
						<h:outputText value="Nenhuma resposta. Participe agora!" rendered="#{enqueteMB.description == 'nenhum'}"/>
						<c:choose>
							<c:when test="#{enqueteMB.description == 'tem'}">																								
								Sim: <h:outputText value="#{enqueteMB.percentualSimFormat}"/>%
								<rich:progressBar mode="ajax" value="#{enqueteMB.percentualSim}" interval="500" 
           							 minValue="0" maxValue="100" >
           						</rich:progressBar>									           					
																									
								Não: <h:outputText value="#{enqueteMB.percentualNaoFormat}"/>%
								<rich:progressBar mode="ajax" value="#{enqueteMB.percentualNao}" interval="500" 
           							minValue="0" maxValue="100">
           						</rich:progressBar>
           						Total votos: <h:outputText value="#{enqueteMB.votoTotalFormat}"/><br />																														
							</c:when>
							<c:when test="#{enqueteMB.description == 'simMaisQueUm'}">
								Sim: <h:outputText value="100%"/><br/>							
									<rich:progressBar mode="ajax" value="100" interval="500" 
            							 minValue="0" maxValue="100">
            						</rich:progressBar>	            						
            					<h:outputText value="Não: 0%"/><br/>
            					Total votos: <h:outputText value="#{enqueteMB.votoSimFormat}"/><br />	            						
							</c:when>
							<c:when test="#{enqueteMB.description == 'naoMaisQueUm'}">
								<h:outputText value="Sim: 0%"/><br/>
								Não: <h:outputText value="100%"/><br/>							
									<rich:progressBar mode="ajax" value="100" interval="500" 
            							 minValue="0" maxValue="100">
            						</rich:progressBar>
            					Total votos: <h:outputText value="#{enqueteMB.votoNaoFormat}"/><br />	
							</c:when>
							<c:when test="#{enqueteMB.description != 'nenhum'}">							
								<c:if test="#{enqueteMB.description == 'sim'}">
									<h:outputText value="Sim: 100%"/><br/>
									<rich:progressBar mode="ajax" value="100" interval="500" 
            							 minValue="0" maxValue="100">
            						</rich:progressBar>
								</c:if>
								<c:if test="#{enqueteMB.description == 'nao'}">
									<h:outputText value="Sim: 0%"/><br/>									 
								</c:if>
								<c:if test="#{enqueteMB.description == 'nao'}">
									<h:outputText value="Não: 100%"/><br/>
									<rich:progressBar mode="ajax" value="100" interval="500" 
            							 minValue="0" maxValue="100">
            						</rich:progressBar>
            						<h:outputText value="Total votos: 1"/><br/>
								</c:if>
								<c:if test="#{enqueteMB.description == 'sim'}">
									<h:outputText value="Não: 0%"/><br/> 
            						<h:outputText value="Total votos: 1"/><br/>            						
								</c:if>											
							</c:when>
						</c:choose>						
						<h:commandButton value="voltar" action="#{enqueteMB.voltar}"/>					
					</a4j:region>
					</h:form>
										
				</div>	
		</div>


		<ui:insert name="body" />

		<rich:popupPanel id="modalProcessando" modal="true" width="200"
			shadowOpacity="0.0" height="100" autosized="false" resizeable="false">
			<h:panelGroup style="padding:10px">
				<h:panelGrid columns="2" border="0">
					<h:graphicImage url="/resources/images/Processando.gif" />
					<h:outputText value="Processando..." />
				</h:panelGrid>
			</h:panelGroup>
		</rich:popupPanel>
	</div>
	<ui:include src="/WEB-INF/template/barraInferior.xhtml" />

</h:body>
</html>